package com.web.controller;

import com.core.dto.WorkOverTimeDTO;
import com.service.user.WorkOverTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2017/2/17
 * Time: 14:49
 * To change this template use Editor | File and Code Templates.
 */
@Controller
@RequestMapping("/work")
public class WorkOverTimeController {

    @Autowired
    private WorkOverTimeService workOverTimeService;

    @RequestMapping(value = "add", method = RequestMethod.GET)
    public ModelAndView showSaveWorkOverTime() {
        return new ModelAndView("front/workOverTimeUpdate", "workOverTimeDTO", new WorkOverTimeDTO());
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public String saveWorkOverTime(WorkOverTimeDTO workOverTimeDTO) {
        workOverTimeService.saveOrUpdateWorkOverTime(workOverTimeDTO);
        return "redirect:/work/list";
    }

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public String workOverTimeList() {
        return "/front/workOverTime";
    }

    @RequestMapping(value = "list/{currentPage}", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> workOverTimeList(@PathVariable String currentPage) {
        return workOverTimeService.findAllWorkOverTime(currentPage);
    }

    @RequestMapping(value = "update/{workOverTimeGuid}", method = RequestMethod.GET)
    @ResponseBody
    public ModelAndView showUpdateWorkOverTimePage(@PathVariable String workOverTimeGuid) {
        WorkOverTimeDTO workOverTimeDTO = workOverTimeService.findWorkOverTimeByGuid(workOverTimeGuid);
        return new ModelAndView("/front/workOverTimeUpdate", "workOverTimeDTO", workOverTimeDTO);
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public String updateWorkOverTime(WorkOverTimeDTO workOverTimeDTO) {
        workOverTimeService.saveOrUpdateWorkOverTime(workOverTimeDTO);
        return "redirect:/work/list";
    }

    @RequestMapping(value = "del/{workOverTimeGuid}", method = RequestMethod.GET)
    @ResponseBody
    public boolean delWorkOverTimeByGuid(@PathVariable String workOverTimeGuid) {
        return workOverTimeService.delWorkOverTimeByGuid(workOverTimeGuid);
    }


}
